1055563
[xen.git] /
1 /******************************************************************************
2  * hvm/emulate.h
3  * 
4  * HVM instruction emulation. Used for MMIO and VMX real mode.
5  * 
6  * Copyright (c) 2008 Citrix Systems, Inc.
7  * 
8  * Authors:
9  *    Keir Fraser <keir@xen.org>
10  */
11
12 #ifndef __ASM_X86_HVM_EMULATE_H__
13 #define __ASM_X86_HVM_EMULATE_H__
14
15 #include <xen/config.h>
16 #include <xen/err.h>
17 #include <asm/hvm/hvm.h>
18 #include <asm/x86_emulate.h>
19
20 struct hvm_emulate_ctxt {
21     struct x86_emulate_ctxt ctxt;
22
23     /* Cache of 16 bytes of instruction. */
24     uint8_t insn_buf[16];
25     unsigned long insn_buf_eip;
26     unsigned int insn_buf_bytes;
27
28     struct segment_register seg_reg[10];
29     unsigned long seg_reg_accessed;
30     unsigned long seg_reg_dirty;
31
32     bool_t exn_pending;
33     struct hvm_trap trap;
34
35     uint32_t intr_shadow;
36
37     bool_t set_context;
38 };
39
40 enum emul_kind {
41     EMUL_KIND_NORMAL,
42     EMUL_KIND_NOWRITE,
43     EMUL_KIND_SET_CONTEXT_DATA,
44     EMUL_KIND_SET_CONTEXT_INSN
45 };
46
47 int hvm_emulate_one(
48     struct hvm_emulate_ctxt *hvmemul_ctxt);
49 int hvm_emulate_one_no_write(
50     struct hvm_emulate_ctxt *hvmemul_ctxt);
51 void hvm_emulate_one_vm_event(enum emul_kind kind,
52     unsigned int trapnr,
53     unsigned int errcode);
54 void hvm_emulate_prepare(
55     struct hvm_emulate_ctxt *hvmemul_ctxt,
56     struct cpu_user_regs *regs);
57 void hvm_emulate_init(
58     struct hvm_emulate_ctxt *hvmemul_ctxt,
59     const unsigned char *insn_buf,
60     unsigned int insn_bytes);
61 void hvm_emulate_writeback(
62     struct hvm_emulate_ctxt *hvmemul_ctxt);
63 struct segment_register *hvmemul_get_seg_reg(
64     enum x86_segment seg,
65     struct hvm_emulate_ctxt *hvmemul_ctxt);
66 int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla);
67
68 int hvmemul_insn_fetch(enum x86_segment seg,
69                        unsigned long offset,
70                        void *p_data,
71                        unsigned int bytes,
72                        struct x86_emulate_ctxt *ctxt);
73 int hvmemul_do_pio_buffer(uint16_t port,
74                           unsigned int size,
75                           uint8_t dir,
76                           void *buffer);
77
78 void hvm_dump_emulation_state(const char *prefix,
79                               struct hvm_emulate_ctxt *hvmemul_ctxt);
80
81 #endif /* __ASM_X86_HVM_EMULATE_H__ */
82
83 /*
84  * Local variables:
85  * mode: C
86  * c-file-style: "BSD"
87  * c-basic-offset: 4
88  * tab-width: 4
89  * indent-tabs-mode: nil
90  * End:
91  */